package com.junjie.checkin.entity.Enum;

import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.Getter;

import java.util.Arrays;

/**
 * @author 洪浚杰
 * @description 活动状态枚举
 * @date 2025/6/13 14:36
 */
@Getter
public enum ActivityStatusEnum implements StringValuedEnum {
    DRAFT("draft", 1),
    PUBLISHED("published", 2),
    ONGOING("ongoing", 3),
    ENDER("ended", 4),
    CANCELED("cancelled", 5);

    private final String value;
    private final int index;

    ActivityStatusEnum(String value, int index) {
        this.value = value;
        this.index = index;
    }

    @Override
    public String getValue() {
        return value;
    }



    @JsonCreator
    public static ActivityStatusEnum fromValue(String value) {
        return Arrays.stream(values())
                .filter(e -> e.getValue().equalsIgnoreCase(value))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("Invalid value: " + value));
    }
    public static ActivityStatusEnum fromIndex(int index) {
        for (ActivityStatusEnum e : values()) {
            if (e.getIndex() == index) {
                return e;
            }
        }
        throw new IllegalArgumentException("No enum constant for index: " + index);
    }
}